"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".

Replace this with more appropriate tests for your application.
"""

from django.test import TestCase
from svn.models import Repository
from svn import command

from collections import OrderedDict
class SimpleTest(TestCase):
   def test_basic_addition(self):
        """
        Tests that 1 + 1 always equals 2.
        """
        self.assertEqual(1 + 1, 2)

   def test_set_up_repository(self):
   		'''
   		Test setting up model object Repository and check whether it exists in the database.
   		'''
   		newRepo = Repository.objects.create(root="file:///Users/eternalcharlie/Documents/project_showcase/peripheral/svnroot",label="test",username="charlie",password="dummyderp")
   		self.assertTrue(Repository.objects.get(label="test"))

   def test_checkout_file(self):
   		'''
   		Test command function checkout_file and whether it returns the content of the file.
   		'''
   		text = command.checkout_file(path="file:///Users/eternalcharlie/Documents/project_showcase/peripheral/svnroot", filename="test", username="charlie",password="dummyderp", hashtimestamp="aaaaaaaaaa")
   		self.assertEqual("ahaha\n", text)
   def test_get_next_level(self):
   		'''
   		Test command function get_next_level and whether it returns the immediate children of a path.
   		'''
   		next_lvl = command.get_next_level(path="file:///Users/eternalcharlie/Documents/project_showcase/peripheral/svnroot", username="charlie", password="dummyderp")
   		self.assertEqual(OrderedDict([(u'@kind', u'file'), (u'name', u'test'), (u'size', u'6'), (u'commit', OrderedDict([(u'@revision', u'1'), (u'author', u'eternalcharlie'), (u'date', u'2012-11-15T19:06:27.733226Z')]))]), next_lvl)

   def test_savefile(self):
   		'''
   		Test command function savefile and whether retrieving the file returns the correct value. 
   		'''
   		nullreturn = command.savefile(content="sadface:(", path="file:///Users/eternalcharlie/Documents/project_showcase/peripheral/svnroot", filename="test", username="charlie", password="dummyderp", hashtimestamp="aaaaaaaaaa")
   		text = command.checkout_file(path="file:///Users/eternalcharlie/Documents/project_showcase/peripheral/svnroot", filename="test", username="charlie",password="dummyderp", hashtimestamp="aaaaaaaaaa")
   		self.assertEqual("sadface:(", text)

   def test_savefile_and_commit(self):
   		'''
   		Test command function savefile with valid commit message, which enables commiting changes to svn. 
   		'''
   		nullreturn = command.savefile(content="happyface:)", path="file:///Users/eternalcharlie/Documents/project_showcase/peripheral/svnroot", filename="test", username="charlie", password="dummyderp", hashtimestamp="aaaaaaaaaa", commitmessage="break is coming, why you so sad")
   		text = command.checkout_file(path="file:///Users/eternalcharlie/Documents/project_showcase/peripheral/svnroot", filename="test", username="charlie",password="dummyderp", hashtimestamp="aaaaaaaaaa")
   		self.assertEqual("happyface:)", text)

   def test_reset_change(self):
   		'''
   		Test command function reset_change on a modified file and check whether file is restored as in svn.
   		'''
   		nullreturn = command.savefile(content="euphoriaface=v=", path="file:///Users/eternalcharlie/Documents/project_showcase/peripheral/svnroot", filename="test", username="charlie", password="dummyderp", hashtimestamp="aaaaaaaaaa")
   		text = command.reset_change(path="file:///Users/eternalcharlie/Documents/project_showcase/peripheral/svnroot", filename="test", username="charlie", password="dummyderp", hashtimestamp="aaaaaaaaaa")
   		self.assertEqual("happyface:)", text)
